import { defineStore } from "pinia"
import axios from "axios"
import { nanoid } from "nanoid"

export const useTalkStore = defineStore('talk',{
    actions:{
         getATalk(){
            // let {data:{content}} =  await axios.get('https://api.uomg.com/api/rand.qinghua?format=json')
			// console.log(content);
			// let obj = {id:nanoid(),title:content}
			// this.talkList.unshift(obj)
            console.log("@ send xhttp");
            axios.get('https://api.uomg.com/api/rand.qinghua?format=json').then(resp=>{
                let obj = {id:nanoid(),title:resp.data.content}
			this.talkList.unshift(obj)
            }).catch(error=>{
                console.log(error);
            })
			
        }
    },
    state() {
        return {
            talkList:JSON.parse(localStorage.getItem('talkList') as string ) || []
        }
    },
})